﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace NGUYENTHANHDONG.Excercise_lv2.Bai1
{
    public partial class Triangle : Form
    {
        public Triangle()
        {
            InitializeComponent();
        }

        private void btnXacNhan_Click(object sender, EventArgs e)
        {
            errorProvider1.Clear();

            if (string.IsNullOrEmpty(txtSide1.Text))
            {
                errorProvider1.SetError(txtSide1, "Khong dc de trong !!");
                txtSide1.Focus();
            }
            else if(string.IsNullOrEmpty(txtSide2.Text))
            {
                errorProvider1.SetError(txtSide2, "Khong dc de trong !!");
                txtSide2.Focus();
            }
            else if(string.IsNullOrEmpty(txtSide3.Text))
            {
                errorProvider1.SetError(txtSide3, "Khong dc de trong !!");
                txtSide3.Focus();
            }
            else
            {
                UserEntity objUser;
                CONTROLLERS con = new CONTROLLERS();
                if(cmbChonKieu.Text == "Diện Tích")
                {
                    objUser = new UserEntity(double.Parse(txtSide1.Text), double.Parse(txtSide2.Text), double.Parse(txtSide3.Text), 1);
                    txtKetQua.Text = con.TinhToan(objUser) + " ";
                }
                else
                {
                    objUser = new UserEntity(double.Parse(txtSide1.Text), double.Parse(txtSide2.Text), double.Parse(txtSide3.Text), 2);
                    txtKetQua.Text = con.TinhToan(objUser) + " ";
                }
            }
        }

        private void Triangle_Load(object sender, EventArgs e)
        {
            cmbChonKieu.Items.Add("Diện Tích");
            cmbChonKieu.Items.Add("Chu Vi");
            cmbChonKieu.SelectedIndex = 0;
        }
    }
}
